package com.xx.springboot.designPattern.ObserverMode;

import java.util.Observable;

/**
 * Created by xiaoxiunique on 2018-11-13.
 */
public class CurrentConditionDisplay implements java.util.Observer, DisplayElement {

    Observable observable;

    /**
     * 温度
     */
    private float temperature;

    /**
     * 湿度
     */
    private float humidity;

    public CurrentConditionDisplay(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println("温度:" + this.temperature);
    }

    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof JWetherData) {
            JWetherData wetherData = (JWetherData) o;
            this.temperature = wetherData.getTemperature();
            this.humidity = wetherData.getHumidity();
            display();
        }
    }
}


